﻿using System;

namespace Program19
{
    class Program
    {
        static void Main(string[] args)
        {
            //1.用方法来实现：有一个字符串数组：{ "马龙", "迈克尔乔丹", "雷吉米勒", "蒂姆邓肯", "科比布莱恩特" },请输出最长的字符串。
            string[] names = { "马龙", "迈克尔乔丹", "雷吉米勒",  "科比布莱恩特","蒂姆邓肯" };
            string max = GetLongestzfc(names);
            Console.WriteLine("最长的字符串是:{0}", max);

            //2.用方法来实现：请计算出一个整型数组的平均值。{ 1, 3, 5, 7, 93, 33, 4, 4, 6, 8, 10 }。要求：计算结果如果有小数，则显示小数点后两位（四舍五入）。
            int[] nums = { 1, 3, 5, 7, 93, 33, 4, 4, 6, 8, 10 };
            double average = GetAverage(nums);
            Console.WriteLine("这组的平均值为：{0:0.00}", average);


            //3.请通过冒泡排序法对整数数组{ 1, 3, 5, 7, 90, 2, 4, 6, 8, 10 }实现升序排序。
            int[] numbers = { 1, 3, 5, 7, 90, 2, 4, 6, 8, 10 };
            Aceeding(numbers);

        }

        /// <summary>
        /// 取最长的字符串
        /// </summary>
        /// <param name="names"></param>
        /// <returns></returns>
        public static string GetLongestzfc(string[] names)
        {
            string Longest = names[0];
            for (int i = 0; i < names.Length; i++)
            {
                if (names[i].Length > Longest.Length)
                {
                    Longest = names[i];
                }
            }

            return Longest;

        }
        /// <summary>
        /// 求平均值
        /// </summary>
        /// <param name="nums"></param>
        /// <returns></returns>
        public static double GetAverage(int[] nums)
        {
            double sum = 0;
            double average = 0;

            for (int i = 0; i < nums.Length; i++)
            {
                sum += nums[i];
            }
            average= sum / nums.Length;
            return average;
        }


        public static void Aceeding(int[] nums)
        {
            Console.WriteLine("排序前：");
            for (var i=0;i<nums.Length;i++)
            {
                Console.Write(nums[i]+" ");
            }
            Console.WriteLine();
            Console.WriteLine("排序后：");
            for (int i = 0; i < nums.Length; i++)
            {
                for (var j = 0; j < nums.Length - 1 - i; j++)
                {
                    if (nums[j] > nums[j + 1])
                    {
                        int temp = nums[j];
                        nums[j] = nums[j+1];
                        nums[j+1 ] = temp;
                    }
                }
            }
            for (var i = 0; i < nums.Length; i++)
            {
                Console.Write(nums[i]+" ");
            }
            Console.WriteLine();
       

        }

    }
}
